﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
using UIControls.Core;

namespace UIControls
{
    public class CsTextBox : LabelCell, IUIControl
    {
        public TextBox TextBox;
    
        public CsTextBox()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.BackColor = Color.Transparent;
            this.Font = GlobalUIVar.gFont;
            TextBox.Font = this.Font;
            
        }
        public void BindTo(object obj, string propertyName)
        {
            this.TextBox.DataBindings.Add("Text", obj, propertyName);
        }
        /// <summary>
        /// Inner Control Text
        /// </summary>
        public new string Text
        {
            get { return TextBox.Text; }
            set { TextBox.Text = value; }
        }
      
        protected override Size DefaultSize
        {
            get
            {
                return new Size(250, 30);
            }
        }
        protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
        {
            base.SetBoundsCore(x, y, width, DefaultSize.Height, specified);
        }
     
     
        public string LabelText
        {
            get {
                return base.Text;
            }
            set
            {
                base.Text = value;
            }
        }
        private int _LabelWidth=100;
        public int LabelWidth
        {
            get { return _LabelWidth; }
            set
            {
                _LabelWidth = value;
            }
        }
        protected override void OnLayout(LayoutEventArgs levent)
        {
            if (TextBox == null)
                return;
            TextBox.Location = new Point( this.LabelWidth,5);
            
            TextBox.Width = this.Width - this.LabelWidth;
        }
     
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.DrawString(this.LabelText, this.Font, new SolidBrush(GlobalUIVar.gLabelColor), new Point(e.ClipRectangle.Left + 5, e.ClipRectangle.Top + 10));         
            
        }

        private void InitializeComponent()
        {
            this.TextBox = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            // 
            // TextBox
            // 
            this.TextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.TextBox.Location = new System.Drawing.Point(100,5);
            this.TextBox.Name = "TextBox";
            this.TextBox.Size = new System.Drawing.Size(150, 20);
            this.TextBox.TabIndex = 0;
            // 
            // CsTextBox
            // 
            this.Controls.Add(this.TextBox);
            
            this.ResumeLayout(false);
            this.PerformLayout();

        }
     
    }
}
